<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a4j="http://richfaces.org/a4j"
                template="../../layout/site-template.xhtml">

    <ui:define name="head-title">
        <title>GLXN - Home of Ken Gullaksen</title>
    </ui:define>

    <ui:define name="menu">
        <ui:include src="../includes/menu/menuform.xhtml"/>
    </ui:define>

    <ui:define name="page-title">
        <h2>Create a page</h2>
    </ui:define>

    <ui:define name="left-content">
        existing pages:
        <ul>
            <ui:repeat var="_parent" value="#{pageList.parentPages}">
                <li class="page">
                    <span>
                        <s:link value="#{_parent.title}"
                                view="/page.xhtml"
                                title="#{_parent.title}">
                            <f:param name="pageId" value="#{_parent.id}"/>
                        </s:link>
                    </span>
                </li>
            </ui:repeat>
        </ul>
    </ui:define>

    <ui:define name="main-content-body">
        <h:form id="pageform" styleClass="ki-form">
            <fieldset class="columnar label-top">

                <h:outputLabel value="title:"
                               for="title"/>
                <h:inputText id="title"
                             value="#{pageHome.instance.title}"/>
                <rich:editor id="pageeditor"
                             value="#{pageHome.instance.content}"
                             theme="advanced"
                             height="275">
                </rich:editor>

                <a4j:outputPanel rendered="#{!empty pageList.resultList}"
                                 id="parentSetter">
                    <h:outputLabel for="parentSetBool" value="set parent page:"/>
                    <h:selectBooleanCheckbox value="#{setParent}" id="parentSetBool">
                        <a4j:support event="onchange" reRender="parentSetter" ajaxSingle="true"/>
                    </h:selectBooleanCheckbox>
                    <f:subview id="parentSelector"
                               rendered="#{setParent}">
                        <h:outputLabel value="parent:"
                                       for="parent"/>
                        <h:selectOneMenu value="#{pageHome.instance.parent}"
                                         id="parent"
                                         required="#{setParent}">
                            <s:selectItems value="#{pageList.resultList}" var="_page" label="#{_page.title}"
                                           noSelectionLabel="pick parent"/>
                            <s:convertEntity/>
                        </h:selectOneMenu>
                    </f:subview>
                </a4j:outputPanel>

                <a4j:outputPanel rendered="#{!empty fileSetList.resultList}"
                                 id="filesetSetter">
                    <h:outputLabel for="addFileSetBool" value="add fileset:"/>
                    <h:selectBooleanCheckbox value="#{addFileSet}" id="addFileSetBool">
                        <a4j:support event="onchange" reRender="filesetSetter" ajaxSingle="true"/>
                    </h:selectBooleanCheckbox>
                    <f:subview id="filesetSelector"
                               rendered="#{addFileSet}">
                        <h:outputLabel value="fileset:"
                                       for="fileset"/>
                        <h:selectOneMenu value="#{pageHome.instance.fileSet}"
                                         id="fileset"
                                         required="#{addFileSet}">
                            <s:selectItems value="#{fileSetList.resultList}" var="_fileSet" label="#{_fileSet.name}"
                                           noSelectionLabel="pick fileset"/>
                            <s:convertEntity/>
                        </h:selectOneMenu>
                        <h:selectOneRadio value="#{pageHome.instance.fileSetPosition}"
                                          required="#{addFileSet}">
                            <f:selectItem itemValue="pre" itemLabel="pre"/>
                            <f:selectItem itemValue="post" itemLabel="post"/> 
                        </h:selectOneRadio>
                    </f:subview>
                </a4j:outputPanel>

            </fieldset>
            <fieldset class="buttons">
                <h:commandButton id="save"
                                 value="Save"
                                 action="#{pageHome.persist}"
                                 rendered="#{!pageHome.managed}"/>
                <h:commandButton id="update"
                                 value="Save"
                                 action="#{pageHome.update}"
                                 rendered="#{pageHome.managed}"/>
                <h:commandButton id="delete"
                                 value="Delete"
                                 action="#{pageHome.remove}"
                                 immediate="true"
                                 rendered="#{pageHome.managed}"/>
                <s:button propagation="end"
                          id="cancel"
                          value="Cancel"
                          view="/home.xhtml"/>
            </fieldset>

        </h:form>
    </ui:define>

    <ui:define name="footer">
        <h4>adm 'at' glxn.net </h4>
    </ui:define>
</ui:composition>
